| {% extends "background/base.html" %}
block pagetitle
	| : 书籍搜索
- block content
	#NAVID(data-nav="booksearch")
	.row
		.col-xs-12
			.panel.panel-primary
				.panel-heading 书籍搜索
				.panel-body
					form.form-inline(action=".",method="GET")
						.form-group
							label.sr-only.control-label(for="search") 关键词
							input#search.form-control(placeholder="关键词",type="text",value="{{query_text|default_if_none:''}}",name="q")
						.form-group
							label.sr-only.control-label(for="category") 分类
							select#category.form-control(type="text",name="cq")
								if cq == 'all'
									option(value="all",selected) 所有分类
								else
									option(value="all") 所有分类
								for c in categorys
									if cq == c.name
										option(value="{{c.name}}",selected) {{c.name}}
									else
										option(value="{{c.name}}") {{c.name}}
						.form-group
							label.sr-only.control-label(for="order") 排序
							select#order.form-control(type="text",name="od")
								for k in orderkey
									if ordered == k.val
										option(value="{{k.val}}",selected) {{k.name}}
									else
										option(value="{{k.val}}") {{k.name}}
						button.btn.btn-success.btn-sm(type="submit") 提交
						.btn-group.pull-right.btn-flat(style="margin:0;")
							a.btn.btn-primary.btn-sm.withripple(href="javascript:;") 批量操作
								.ripple-wrapper
							a.btn.btn-primary.btn-sm.dropdown-toggle.withripple(href="javascript:;",data-toggle="dropdown")
								span.caret
								.ripple-wrapper
							ul.dropdown-menu
								li
									a(href="{% url 'bbg:book_jiuzhenggengxin' %}") 自动纠新
								li
									a(href="{% url 'bbg:book_page_next_zipper' %}") 修复中断章节
					if books
						table.table
							thead
								tr
									th 书名
									th 作者
									th(style="width:73px;") 分类
									th(style="width:450px;") 章节
									th(style="width:75px;") 更新时间
									th 操作
							tbody
								for book in books
									tr
										td(title=book.book_number)= book.title
											br
											a.btn.btn-xs.btn-success(title=book.title,tabindex="0",role="button",data-toggle="popover",data-trigger="focus",data-content="{{book.info}}") 简介
										td= book.author
										td= book.category
										td
											span 最新：
											a.new(href="{{book.last_page.get_absolute_url}}",target="_blank")= book.last_page.title_html
											br
											span 最后：
											a.last(href="{{book.get_last_page.get_absolute_url}}",target="_blank")= book.get_last_page.title_html
										td= book.last_update|date:"y-m-d"
										td
											a.btn.btn-xs.btn-info.bookjx(href="javascript:;",data-bookid=book.id,title="纠正最新章节",data-toggle="tooltip",data-placement="top") 纠新
											br
											a.btn.btn-xs.btn-info.bookft(href="javascript:;",data-bookid=book.id,title="封面推荐本书",data-toggle="tooltip",data-placement="left") 封推
											br
											a.btn.btn-xs.btn-info.bookjt(href="javascript:;",data-bookid=book.id,title="精品推荐本书",data-toggle="tooltip",data-placement="left") 精推
					if pagination.has_other_pages
						.col-md-12.col-xs-12.col-sm-12.text-center
							ul.pagination
								if pagination.has_previous
									li
										a(href="#",data-num="1") &lt;&lt;
									li
										a(href="#",data-num="{{pagination.previous_page_number}}") &lt;
								li.active
									span= pagination.number
								if pagination.has_next
									li
										a(href="#",data-num="{{pagination.next_page_number}}") &gt;
									li
										a.fui-arrow-right(href="#",data-num="{{pagination.paginator.num_pages}}") &gt;&gt;
								li.disabled: a(href="javascript:;") 共（{{pagination.paginator.num_pages}}）页，{{pagination.paginator.count}}条数据
block footerjs
	script
		$(function () {
			$('[data-toggle="tooltip"]').tooltip();
			$('[data-toggle="popover"]').popover();
			$('.bookjx').click(function(){
				var bookid = $(this).data('bookid');
				var last_page = $(this).parents('tr').find("span.last").eq(0);
				var new_page = $(this).parents('tr').find("span.new").eq(0);
				$.ajax({
					url: "{% url 'bbg:book_jx' %}",
					method: "POST",
					dataType: 'json',
					data: {book_id:bookid},
					success: function(data){
						new_page.text(last_page.text());
						alert("纠正新章节成功！");
					},
					error: function(xhr,status,error){
						alert("请求失败！Status: "+status+" Content: "+xhr.responseText);
					}
				});
				return false;
			});
			$('.bookft').click(function(){
				var bookid = $(this).data('bookid');
				$.ajax({
					url: "{% url 'bbg:book_ft' %}",
					method: "POST",
					dataType: 'json',
					data: {book_id:bookid},
					success: function(data){
						alert("封推成功！");
					},
					error: function(xhr,status,error){
						alert("请求失败！Status: "+status+" Content: "+xhr.responseText);
					}
				});
				return false;
			});
			$('.bookjt').click(function(){
				var bookid = $(this).data('bookid');
				$.ajax({
					url: "{% url 'bbg:book_jt' %}",
					method: "POST",
					dataType: 'json',
					data: {book_id:bookid},
					success: function(data){
						alert("精推成功！");
					},
					error: function(xhr,status,error){
						alert("请求失败！Status: "+status+" Content: "+xhr.responseText);
					}
				});
				return false;
			});
		})
